#pragma once

#include <boost/shared_ptr.hpp>

#include "hard_disk_controller.h"

using namespace boost;

class HardDiskController;

/* Wrapper class
 * Wraps a given process and enables execution of IN/OUT opcodes.
 * Implementation: This class actually debugs (with PTRACE) a given process 
 * and properly handle the exception being raised by the IN/OUT opcodes.
 */
class Wrapper {
    private:
        /* the process id of the debuged child */
        pid_t child;
        /* pointer to our HardDiskController instance */
        shared_ptr<HardDiskController> hd;
        /* handled segmentation fault on debuggee */
        void handleSEGV();
    public:
        /* reads one machine word from the debuggee memory */
        uint readWord(uint address);
        /* writes one machine word from the debuggee memory */
        void writeWord(uint address, uint data);
        /* memcpy from this address space to the debuggee memory */
        void memRead(void* localDest, uint remoteSrc, uint size);
        /* memcpy from debuggee memory to this address space to */
        void memWrite(uint remoteDst, void* localSrc, uint size);
        /* c'tor */
        Wrapper(pid_t child);
        ~Wrapper();
        /* mainLoop */
        void run();
};